import datetime


def generate_insert_sql(data,table_name):
    new = dict()
    for k,v in data.items():
        if v is None:
            v = '$NULL$'
        if isinstance(v,datetime.datetime):
            v = v.strftime('%Y-%m-%d %H:%M:%S')
        new[k] = v
    sql = f"""insert into {table_name} {str(tuple(new.keys())).replace("'","")} values {str(tuple(new.values()))};"""
    sql = sql.replace("'$NULL$'","NULL")
    return sql

def generate_influx_sql(data,table_name):
    new = dict()
    for k,v in data.items():
        if v is None:
            v = '$NULL$'
        if isinstance(v,datetime.datetime):
            v = v.strftime('%Y-%m-%d %H:%M:%S')
        new[k] = v
    sql = f"""insert into {table_name} {str(tuple(new.keys())).replace("'","")} values {str(tuple(new.values()))};"""
    sql = sql.replace("'$NULL$'","NULL")
    return sql
